using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using HengTong.Model.Db.System;
using TiaoTaoHelper.Wtm.Models;


namespace HengTong.ViewModel.Common.SysSealVms
{
    public partial class SysSealListVm : BasePagedListVM<SysSealView, SysSealSearcher>
    {

        protected override IEnumerable<IGridColumn<SysSealView>> InitGridHeader()
        {
            return new List<GridColumn<SysSealView>>{
                this.MakeGridHeader(x => x.SealName),
                this.MakeGridHeader(x => x.SealCode),
                this.MakeGridHeader(x => x.OrgName),
                this.MakeGridHeader(x => x.GroupName),
                this.MakeGridHeader(x => x.SealType),
                this.MakeGridHeader(x => x.SealImage),
                this.MakeGridHeader(x => x.Status),
                this.MakeGridHeader(x => x.UseCount),
                this.MakeGridHeader(x => x.LastUseTime),
                this.MakeGridHeader(x => x.Remarks),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysSealView> GetSearchQuery()
        {
            var query = DC.Set<SysSeal>()
                .CheckEqual(Searcher.OrgId, x=>x.OrgId)
                .CheckEqual(Searcher.GroupId, x=>x.GroupId)
                .CheckEqual(Searcher.SealType, x=>x.SealType)
                .CheckEqual(Searcher.Status, x=>x.Status)
                .Select(x => new SysSealView
                {
				    ID = x.ID,
                    SealName = x.SealName,
                    SealCode = x.SealCode,
                    OrgName = x.Org.Name,
                    GroupName = x.Group.GroupName,
                    SealType = x.SealType,
                    SealImage = x.SealImage,
                    Status = x.Status,
                    UseCount = x.UseCount,
                    LastUseTime = x.LastUseTime,
                    Remarks = x.Remarks,
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class SysSealView : SysSeal{
        [Display(Name = "组织名称")]
        public String OrgName { get; set; }
        [Display(Name = "_Admin.GroupName")]
        public String GroupName { get; set; }

    }
}
